package com.fc.test.service;

import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.ConvertUtil;
import com.fc.test.mapper.auto.PaperRecordsMapper;
import com.fc.test.model.auto.PaperRecords;
import com.fc.test.model.auto.PaperRecordsExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 *  PaperRecordsService
 * @Title: PaperRecordsService.java 
 * @Package com.fc.test.service 
 * @author 谢志恺_自动生成
 * @email 2251719256@qq.com
 * @date 2020-10-28 17:25:15  
 **/
@Service
public class PaperRecordsService implements BaseService<PaperRecords, PaperRecordsExample>{
	@Autowired
	private PaperRecordsMapper paperRecordsMapper;
	
      	   	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<PaperRecords> list(Tablepar tablepar,PaperRecords record){
	        PaperRecordsExample testExample=new PaperRecordsExample();
			//搜索
			if(StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
	        	testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
	        }else {//大搜索
	        	testExample.createCriteria().andLikeQuery(record);
	        }
			//表格排序
			if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        }else{
	        	testExample.setOrderByClause("id ASC");
	        }
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<PaperRecords> list= paperRecordsMapper.selectByExample(testExample);
	        PageInfo<PaperRecords> pageInfo = new PageInfo<PaperRecords>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
					
			Integer[] integers = ConvertUtil.toIntArray(",", ids);
			List<Integer> stringB = Arrays.asList(integers);
			PaperRecordsExample example=new PaperRecordsExample();
			example.createCriteria().andIdIn(stringB);
			return paperRecordsMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public PaperRecords selectByPrimaryKey(String id) {
				
			Integer id1 = Integer.valueOf(id);
			return paperRecordsMapper.selectByPrimaryKey(id1);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(PaperRecords record) {
		return paperRecordsMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(PaperRecords record) {
				
		record.setId(null);
		
				
		return paperRecordsMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(PaperRecords record, PaperRecordsExample example) {
		
		return paperRecordsMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(PaperRecords record, PaperRecordsExample example) {
		
		return paperRecordsMapper.updateByExample(record, example);
	}

	@Override
	public List<PaperRecords> selectByExample(PaperRecordsExample example) {
		
		return paperRecordsMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(PaperRecordsExample example) {
		
		return paperRecordsMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(PaperRecordsExample example) {
		
		return paperRecordsMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param paperRecords
	 * @return
	 */
	public int checkNameUnique(PaperRecords paperRecords){
		PaperRecordsExample example=new PaperRecordsExample();
		example.createCriteria().andConsumptionEqualTo(paperRecords.getConsumption());
		List<PaperRecords> list=paperRecordsMapper.selectByExample(example);
		return list.size();
	}

	/**
	 * 查询一张单据下所有消费记录
	 * @param sheetId
	 * @return
	 */
	public List<PaperRecords> getPaperRecords(int sheetId) {

		return paperRecordsMapper.queryPaperRecords(sheetId);
	}


}
